/**
 * @Description: 所有应用的全局仓库
 *
 * @author: liuxiuqian
 *
 * @date: 2020/6/8
 */

import _cloneDeep from "lodash/cloneDeep";

let gloabalState = {};



export const appStateActions = {

  // 获取数据
  getGlobalState: function onGlobalStateChange() {
    return gloabalState
  },
  // 更新数据
  setGlobalState: function setGlobalState(state={}) {
    if (typeof state === 'object') {
      gloabalState = {...gloabalState,...state}
    }else {
      console.warn('state has not object！');
    }
  },
  // 清除全局数据
  delGlobalState: function delGlobalState() {
    gloabalState = {}
  },

}

export function initGlobalState(state = {}) {
  if (state === gloabalState) {
    console.warn('state has not changed！');
  } else {
    gloabalState = _cloneDeep(state);
  }
  return appStateActions;
}


